import { getStoredLanguage } from './language'

// 中文翻译
const zhMessages = {
  service: {
    expert: {
      title: '服务专家',
      desc: '在线1对1专属客服 010-1132546',
      teamTitle: '专业客服团队',
      teamDesc: '7x24小时为您服务',
      contactTitle: '联系方式',
      phoneTitle: '电话咨询',
      phoneDesc: '010-1132546',
      qqTitle: 'QQ客服',
      qqDesc: '4008008000',
      wechatTitle: '微信客服',
      wechatDesc: 'surftech',
      faqTitle: '热门问题',
      serviceTimeTitle: '服务时间说明',
      onlineServiceTitle: '在线客服',
      onlineServiceDesc: '周一至周五 09:00-21:00\n周末及节假日 10:00-18:00',
      phoneServiceTitle: '电话客服',
      phoneServiceDesc: '7x24小时全天候服务',
      callButton: '电话咨询',
      chatButton: '在线咨询'
    },
    video: {
      title: '在线视频',
      desc: '教学视频线上浏览',
      basicTab: '基础教程',
      advancedTab: '进阶教程',
      playCount: '次播放'
    },
    manual: {
      title: '用户手册',
      desc: '详细描述软件的功能、性能等',
      basicTitle: '基础指南',
      advancedTitle: '高级功能',
      troubleshootTitle: '故障排除',
      readMore: '阅读更多'
    },
    feedback: {
      title: '问题反馈',
      desc: '有任何问题请与我们联系',
      formTitle: '反馈表单',
      typeLabel: '问题类型',
      typePrompt: '请选择问题类型',
      contentLabel: '问题描述',
      contentPlaceholder: '请详细描述您遇到的问题...',
      contactLabel: '联系方式',
      contactPlaceholder: '请留下您的手机号或邮箱',
      submitButton: '提交反馈',
      successMsg: '反馈已提交，我们将尽快处理！',
      typeOptions: {
        bug: '功能异常',
        suggestion: '功能建议',
        other: '其他问题'
      }
    }
  }
}

// 英文翻译
const enMessages = {
  service: {
    expert: {
      title: 'Service Expert',
      desc: 'Online 1-on-1 Customer Service 010-1132546',
      teamTitle: 'Professional Service Team',
      teamDesc: '24/7 Service',
      contactTitle: 'Contact Methods',
      phoneTitle: 'Phone Support',
      phoneDesc: '010-1132546',
      qqTitle: 'QQ Support',
      qqDesc: '4008008000',
      wechatTitle: 'WeChat Support',
      wechatDesc: 'surftech',
      faqTitle: 'FAQ',
      serviceTimeTitle: 'Service Hours',
      onlineServiceTitle: 'Online Support',
      onlineServiceDesc: 'Mon-Fri 09:00-21:00\nWeekends & Holidays 10:00-18:00',
      phoneServiceTitle: 'Phone Support',
      phoneServiceDesc: '24/7 Service',
      callButton: 'Call Service',
      chatButton: 'Online Chat'
    },
    video: {
      title: 'Online Videos',
      desc: 'Browse Tutorial Videos',
      basicTab: 'Basic Tutorials',
      advancedTab: 'Advanced Tutorials',
      playCount: 'views'
    },
    manual: {
      title: 'User Manual',
      desc: 'Detailed description of software features and performance',
      basicTitle: 'Basic Guide',
      advancedTitle: 'Advanced Features',
      troubleshootTitle: 'Troubleshooting',
      readMore: 'Read More'
    },
    feedback: {
      title: 'Feedback',
      desc: 'Contact us for any issues',
      formTitle: 'Feedback Form',
      typeLabel: 'Issue Type',
      typePrompt: 'Please select issue type',
      contentLabel: 'Description',
      contentPlaceholder: 'Please describe your issue in detail...',
      contactLabel: 'Contact Info',
      contactPlaceholder: 'Please leave your phone or email',
      submitButton: 'Submit Feedback',
      successMsg: 'Feedback submitted, we will process it ASAP!',
      typeOptions: {
        bug: 'Bug Report',
        suggestion: 'Feature Suggestion',
        other: 'Other Issues'
      }
    }
  }
}

// 递归获取嵌套对象的属性值
const getNestedProperty = (obj, path) => {
  const keys = path.split('.')
  let current = obj

  for (const key of keys) {
    if (current === undefined || current === null) {
      return path // 如果路径不存在，返回原始路径
    }
    current = current[key]
  }

  return current || path // 如果值不存在，返回原始路径
}

// 获取翻译
export const translate = (key) => {
  const lang = getStoredLanguage()
  const messages = lang === 'zh' ? zhMessages : enMessages
  
  return getNestedProperty(messages, key)
} 